package io.renren.modules.examination.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.examination.entity.ExaminationQuestionsEntity;
import io.renren.modules.examination.entity.ExaminationResultTypeEntity;
import io.renren.modules.examination.service.ExaminationQuestionsService;
import io.renren.modules.examination.service.ExaminationResultTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 *
 *
 * @author liuzhm
 * @email ztezhmliu@126.com
 * @date 2019-05-27 15:22:54
 */
@RestController
@RequestMapping("examination/questions")
public class ExaminationQuestionsController {
    @Autowired
    private ExaminationQuestionsService examinationQuestionsService;

    /**
     * 列表
     */
    @RequestMapping("/list/{id}")
    //@RequiresPermissions("examination:paper:list")
    public R list(@RequestParam Map<String, Object> params, @PathVariable("id") Integer id){
        PageUtils page = examinationQuestionsService.queryPageByPaperId(params,id);
        System.out.println(page);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    // @RequiresPermissions("course:student:info")
    public R info(@PathVariable("id") Integer id){
        ExaminationQuestionsEntity examinationQuestions = examinationQuestionsService.selectById(id);
        return R.ok().put("examinationQuestions", examinationQuestions);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("course:student:save")
    public R save(@RequestBody ExaminationQuestionsEntity examinationQuestionsEntity){
        examinationQuestionsService.insert(examinationQuestionsEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //  @RequiresPermissions("course:student:update")
    public R update(@RequestBody ExaminationQuestionsEntity examinationQuestionsEntity){
        ValidatorUtils.validateEntity(examinationQuestionsEntity);
        examinationQuestionsService.updateAllColumnById(examinationQuestionsEntity);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //  @RequiresPermissions("course:student:delete")
    public R delete(@RequestBody Integer[] ids){
        examinationQuestionsService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
